package com.noshufou.android.su;

import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.net.LocalSocketAddress.Namespace;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;
import com.noshufou.android.su.provider.PermissionsProvider.Apps;
import java.io.IOException;
import java.io.OutputStream;

public class SuRequestReceiver extends BroadcastReceiver
{
  public static final String EXTRA_ALLOW = "allow";
  public static final String EXTRA_CALLERUID = "caller_uid";
  public static final String EXTRA_CMD = "desired_cmd";
  public static final String EXTRA_SOCKET = "socket";
  public static final String EXTRA_UID = "desired_uid";
  public static final String EXTRA_VERSION_CODE = "version_code";
  private static final String TAG = "Su.SuRequestReceiver";

  private void sendResult(Context paramContext, Intent paramIntent, boolean paramBoolean)
  {
    LocalSocket localLocalSocket = new LocalSocket();
    try
    {
      localLocalSocket.connect(new LocalSocketAddress(paramIntent.getStringExtra("socket"), LocalSocketAddress.Namespace.FILESYSTEM));
      OutputStream localOutputStream = localLocalSocket.getOutputStream();
      if (paramBoolean);
      for (String str = "ALLOW"; ; str = "DENY")
      {
        localOutputStream.write(str.getBytes());
        localOutputStream.flush();
        localOutputStream.close();
        localLocalSocket.close();
        break;
      }
    }
    catch (IOException localIOException)
    {
      Log.e("Su.SuRequestReceiver", "Failed to write to socket", localIOException);
    }
  }

  private void showPrompt(Context paramContext, Intent paramIntent)
  {
    Intent localIntent = new Intent(paramContext, SuRequestActivity.class);
    localIntent.putExtras(paramIntent);
    localIntent.addFlags(268435456);
    paramContext.startActivity(localIntent);
  }

  public void onReceive(Context paramContext, Intent paramIntent)
  {
    SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(paramContext);
    String str = localSharedPreferences.getString("pref_automatic_action", "prompt");
    if (str.equals("deny"))
      sendResult(paramContext, paramIntent, false);
    while (true)
    {
      return;
      if (str.equals("allow"))
      {
        sendResult(paramContext, paramIntent, true);
        continue;
      }
      if (localSharedPreferences.getBoolean("permissions_dirty", false))
      {
        Log.d("Su.SuRequestReceiver", "Database is dirty, check here");
        Log.d("Su.SuRequestReceiver", "uid=? AND exec_uid=? AND exec_cmd=?");
        ContentResolver localContentResolver = paramContext.getContentResolver();
        Uri localUri = PermissionsProvider.Apps.CONTENT_URI;
        String[] arrayOfString1 = new String[1];
        arrayOfString1[0] = "allow";
        String[] arrayOfString2 = new String[3];
        arrayOfString2[0] = String.valueOf(paramIntent.getIntExtra("caller_uid", -1));
        arrayOfString2[1] = String.valueOf(paramIntent.getIntExtra("desired_uid", -1));
        arrayOfString2[2] = String.valueOf(paramIntent.getStringExtra("desired_cmd"));
        Cursor localCursor = localContentResolver.query(localUri, arrayOfString1, "uid=? AND exec_uid=? AND exec_cmd=?", arrayOfString2, null);
        if (localCursor.moveToFirst())
        {
          Log.d("Su.SuRequestReceiver", "Found an entry");
          switch (localCursor.getInt(0))
          {
          default:
            Log.d("Su.SuRequestReceiver", "Prompt");
            showPrompt(paramContext, paramIntent);
          case 1:
          case 0:
          }
        }
        while (true)
        {
          localCursor.close();
          break;
          Log.d("Su.SuRequestReceiver", "Allow");
          sendResult(paramContext, paramIntent, true);
          continue;
          Log.d("Su.SuRequestReceiver", "Deny");
          sendResult(paramContext, paramIntent, false);
          continue;
          Log.d("Su.SuRequestReceiver", "No entry found, prompt");
          showPrompt(paramContext, paramIntent);
        }
      }
      if (localSharedPreferences.getInt("pref_timeout", 0) > 0)
      {
        long l = localSharedPreferences.getLong("active_" + paramIntent.getIntExtra("caller_uid", 0), 0L);
        if (System.currentTimeMillis() < l)
        {
          sendResult(paramContext, paramIntent, true);
          continue;
        }
        showPrompt(paramContext, paramIntent);
        continue;
      }
      showPrompt(paramContext, paramIntent);
    }
  }
}

/* Location:           D:\Development\Decompile_Workspace\슈퍼유저-41\classes_dex2jar.jar
 * Qualified Name:     com.noshufou.android.su.SuRequestReceiver
 * JD-Core Version:    0.6.0
 */